<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
*/

class Setting extends MY_Controller{

	public function __construct() {
		parent::__construct();
		$this->load->model('config_model','set');
		$this->load->library('form_validation');
		if ($this->isAdmin() == false) redirect("admin/login");
	}
	
	public function index($settingid)
	{
		if (!$this->admin_priv('setting_' . $settingid))
		{
			show_error("您没有权限进行此操作！");
		}

		if ($this->input->post())
		{	
			$postdata = $this->input->post();
			$mtime = time();

			foreach ($postdata as $k => $v)
			{
				$this->set->M(array('confval'=>$v,'mtime'=>$mtime), array('confkey'=>$k));
			}
			$admininfo = $this->isAdmin();
			$this->action_log('1',$admininfo['user_id'],"编辑系统设置");
			$retmsg['code'] = '1';
			$retmsg['msg'] = $this->lang->line('comm_sucess_tip');
			exit(json_encode($retmsg));
		}
		else
		{
			$this->_d['setting'] = $this->config->item('setting');
			$this->_d['settingid'] = $settingid;
			$this->_d['list'] = $this->set->L(array('status'=>1, 'cfgcate'=>$settingid), '*', 1000,0, 'sort', 'asc');
			$this->load->view($this->_d['cfg']['tpl__admin'] . 'setting/config', $this->_d);

		}
	}

}